import { assign } from 'lodash';

import { AnyAction } from 'redux';
import ACTIONS from 'constants/course';

const initialState: Record<string, any> = {
  courseList: [],
  lessonList: [],
};

export default (state = initialState, action: AnyAction) => {
  switch (action.type) {
    case ACTIONS.FETCH_LIST_SUCCESS:
      return assign({}, state, {
        courseList: action.response.data.items,
      });

    case ACTIONS.FETCH_LESSON_LIST_SUCCESS:
      return assign({}, state, {
        lessonList: action.response.data.items,
      });

    default:
      return state;
  }
};
